/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ChamaLayout.java
 *
 * Created on 06/01/2012, 12:22:18
 */
package Formularios;

import BD.CriaConexao;
import Metodos.MinimizaTela;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;



/**
 *
 * @author ARMTEC
 */
public class ChamaLayout extends javax.swing.JFrame {
static int id=0;
private Connection conexao;
ChamaCurso a= new ChamaCurso();
ChamaDisciplina b= new ChamaDisciplina();
ChamaSerie c = new ChamaSerie();
ChamaProfessor d= new ChamaProfessor();
ChamaHorasAulas e=new ChamaHorasAulas();
ChamaHorario f= new ChamaHorario();
static int i;
    /** Creates new form ChamaLayout */
    public ChamaLayout() {
       
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormHorasAula.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        try {
            this.conexao=(Connection) CriaConexao.getConexao();
        } catch (SQLException ex) {
            Logger.getLogger(ChamaLayout.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        BufferedImage image=null;
        File imageFile=new File(".\\src\\Imagens\\logo3.png");
        try {
            image=ImageIO.read(imageFile);
            
        } catch (IOException ex) {
        }
        this.setIconImage(image);
        
        i=0;
//        BufferedImage image=new BufferedImage(10,10,BufferedImage.TYPE_INT_ARGB);
//        setIconImage(image);
 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
 a.setBounds((screenSize.width-(253+400))/2, (screenSize.height-(253+440))/2, 300, 201);
 b.setBounds((screenSize.width-(253-300))/2, (screenSize.height-(253+440))/2, 300, 201);
 c.setBounds((screenSize.width-(253-540))/2, (screenSize.height-(253-50))/2, 300, 201);
 d.setBounds((screenSize.width-(253-300))/2, (screenSize.height-(253-540))/2, 300, 201);
 e.setBounds((screenSize.width-(253+400))/2, (screenSize.height-(253-540))/2, 300, 201);
 f.setBounds((screenSize.width-(253+640))/2, (screenSize.height-(253-50))/2, 300, 201);
 
        a.setVisible(true);
        b.setVisible(true);
        c.setVisible(true);
        d.setVisible(true);
        e.setVisible(true);
        f.setVisible(true);
        timer1.start();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        timer1 = new org.netbeans.examples.lib.timerbean.Timer();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        timer1.addTimerListener(new org.netbeans.examples.lib.timerbean.TimerListener() {
            public void onTime(java.awt.event.ActionEvent evt) {
                timer1OnTime(evt);
            }
        });

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SGH");
        setIconImages(null);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowDeiconified(java.awt.event.WindowEvent evt) {
                formWindowDeiconified(evt);
            }
            public void windowIconified(java.awt.event.WindowEvent evt) {
                formWindowIconified(evt);
            }
        });

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/cats.jpg"))); // NOI18N
        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel3MouseClicked(evt);
            }
        });
        jLabel3.setBounds(20, 10, 210, 50);
        jDesktopPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/icone21.png"))); // NOI18N
        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel2MouseClicked(evt);
            }
        });
        jLabel2.setBounds(50, 60, 160, 150);
        jDesktopPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/kakaka.jpg"))); // NOI18N
        jLabel1.setBounds(0, 0, 247, 225);
        jDesktopPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-253)/2, (screenSize.height-253)/2, 253, 253);
    }// </editor-fold>//GEN-END:initComponents

    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseClicked
java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Sobre().setVisible(true);
            }
        });        

    }//GEN-LAST:event_jLabel2MouseClicked

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        a.setDefaultCloseOperation(WIDTH);
        b.setDefaultCloseOperation(WIDTH);
        c.setDefaultCloseOperation(WIDTH);
        d.setDefaultCloseOperation(WIDTH);
        e.setDefaultCloseOperation(WIDTH);
        f.setDefaultCloseOperation(WIDTH);
    }//GEN-LAST:event_formWindowClosed

    private void formWindowDeiconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowDeiconified
MinimizaTela asd= new MinimizaTela();
        try {
            asd.Minimiza(0);
        } catch (SQLException ex) {
            Logger.getLogger(ChamaLayout.class.getName()).log(Level.SEVERE, null, ex);
        }
 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
 a.setBounds((screenSize.width-(253+400))/2, (screenSize.height-(253+440))/2, 300, 201);
 b.setBounds((screenSize.width-(253-300))/2, (screenSize.height-(253+440))/2, 300, 201);
 c.setBounds((screenSize.width-(253-540))/2, (screenSize.height-(253-50))/2, 300, 201);
 d.setBounds((screenSize.width-(253-300))/2, (screenSize.height-(253-540))/2, 300, 201);
 e.setBounds((screenSize.width-(253+400))/2, (screenSize.height-(253-540))/2, 300, 201);
 f.setBounds((screenSize.width-(253+640))/2, (screenSize.height-(253-50))/2, 300, 201);
a.setVisible(true); 
b.setVisible(true); 
c.setVisible(true); 
d.setVisible(true); 
e.setVisible(true); 
f.setVisible(true); 
setVisible(true);

    }//GEN-LAST:event_formWindowDeiconified

    private void formWindowIconified(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowIconified
a.setVisible(false);
b.setVisible(false);
c.setVisible(false);
d.setVisible(false);
e.setVisible(false);
f.setVisible(false);

    }//GEN-LAST:event_formWindowIconified

private void timer1OnTime(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timer1OnTime
String sql = "select * from layout1";
        
  
      
            
            PreparedStatement stmt;
        try {
            stmt = (PreparedStatement) conexao.prepareStatement(sql);
            try (ResultSet rs = stmt.executeQuery()) {
                while (rs.next()){
                    
                    id=rs.getInt("id");
                   
                    
                }
            }
            stmt.close();
        } catch (SQLException ex) {
            Logger.getLogger(ChamaLayout.class.getName()).log(Level.SEVERE, null, ex);
        }
         if(id==1){
             formWindowIconified(null);
             dispose();
         }   
         
}//GEN-LAST:event_timer1OnTime

    private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseClicked
if(i==0){        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Layout().setVisible(true);
            }
        });
i=1;
       }
    }//GEN-LAST:event_jLabel3MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ChamaLayout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ChamaLayout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ChamaLayout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ChamaLayout.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ChamaLayout().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private org.netbeans.examples.lib.timerbean.Timer timer1;
    // End of variables declaration//GEN-END:variables
}
